package cool.tianyou.blue.bird.common.mapper;


import cool.tianyou.blue.bird.common.model.po.User;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;

/**
 * @author Liutianyou
 * @date 2020/11/28 7:41 下午
 */
@org.apache.ibatis.annotations.Mapper
public interface UserMapper extends Mapper<User> {

  /**
   * 校验邮箱是否被注册
   *
   * @param email 邮箱地址
   * @return
   */
  default boolean repeatEmail(String email) {
    final int count = this.selectCountByExample(Example
        .builder(User.class).where(Sqls.custom().andEqualTo("email", email)).build());
    return count != 0;
  }

  default Integer count() {
    return this.selectCountByExample(null);
  }

}
